<?php
/**
 * Created by PhpStorm.
 * User: zeng
 * Date: 18-5-19
 * Time: 上午10:45
 */

namespace App\Http\Controllers;


use App\User;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class RoleController extends Controller
{
    public function addUser()
    {
//        User::create(['name'=>'admin','password'=>bcrypt('123456'),'email'=>'513094459@qq.com']);

//        Role::create(['name' => 'admin']);
//        Permission::create(['name' => 'edit articles']);
        $user=User::find(1);
        if($user->hasRole('admin')){
            echo '该用户拥有admin角色';
        }
        if($user->can('edit articles')){
            echo '该用户可以edit articles';
        }
//        dd($user->getAllPermissions());

    }
    public function addRole(){
        $role=Role::find(1);
        $role->givePermissionTo('edit articles');
    }
}